package com.yxq.mdt.app.modules.publish.ui.presenter;

import com.yxq.mdt.app.base.BasePresenter;
import com.yxq.mdt.app.modules.publish.ui.bean.MainPublishBean;
import com.yxq.mdt.app.modules.publish.ui.bean.PublishListBean;
import com.yxq.mdt.app.modules.publish.ui.model.MainPublishModel;
import com.yxq.mdt.app.net.ApiModel;

import okhttp3.MediaType;
import okhttp3.RequestBody;


public class MainPublishPresenter extends BasePresenter<IMainPublishContract.View, MainPublishModel> implements IMainPublishContract.Presenter {
    /**
     * 如果当前页面同时需要 Model 层和 View 层,则使用此构造函数(默认)
     *
     * @param rootView
     * @param model
     */
    public MainPublishPresenter(IMainPublishContract.View rootView, MainPublishModel model) {
        super(rootView, model);
    }

    /**
     * 上传图片/视频/语音
     */
    @Override
    public void onSetDoPublishList(String data) {
//        String url = data.replaceAll("%(?![0-9a-fA-F]{2})","%25");
        final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

        RequestBody body = RequestBody.create(JSON, data);

        mBaseModel.setDoPublish(body, new ApiModel.CommonCallback<PublishListBean>() {
            @Override
            public void onSuccess(PublishListBean publishListBean) {
                mRootView.onSetDoPublishSuccess(publishListBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onSetDoPublishFailed(errMsg);
            }
        });
    }

}
